
package com.scs.application.modules.base.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.mvc.controller.ImAndExAbleController;
import com.scs.application.modules.base.entity.MaterialInquiryItem;
import com.scs.application.modules.base.request.MaterialInquiryItemQueryRequest;
import com.scs.application.modules.base.service.MaterialInquiryItemService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 耗材询价单明细 controller
 */
@AllArgsConstructor
@RestController
@RequestMapping("/base/material_inquiry_items")
public class MaterialInquiryItemController extends CrudController<MaterialInquiryItem, String, MaterialInquiryItemService> implements ImAndExAbleController<MaterialInquiryItemQueryRequest> {

    @GetMapping("/page")
    public PageResult page(MaterialInquiryItemQueryRequest request) {
        IPage page = service.page(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }

    @GetMapping("/list")
    public CommonResult list(MaterialInquiryItemQueryRequest request) {
        List<MaterialInquiryItem> list = service.list(request);
        return CommonResult.ok("查询成功", list);
    }


    @PutMapping("/batch_save")
    public CommonResult batchSave(@RequestBody @Valid List<MaterialInquiryItem> children) {
        if (children.isEmpty()) {
            return CommonResult.error("保存失败");
        }
        boolean bSuccess = service.saveOrUpdateBatch(children);
        return bSuccess ? CommonResult.ok("保存成功") : CommonResult.error("保存失败");
    }
}
